package bavaria.hightech.formatter;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;


import bavaria.hightech.banking.Account;
import bavaria.hightech.booking.Booking;
import bavaria.hightech.booking.Sortmethod;

public class FormatHtml implements FormatterInterface {

	@Override
	public void createStetement(Account acc, Sortmethod comp) throws IOException {
		
		File file = new File("c:/statement.html");
		
		Collections.sort(acc.getList(), comp.comperator);
		
		Iterator<Booking> iter = acc.getList().iterator();
		
		BufferedWriter bw = new BufferedWriter(new FileWriter(file));
		
		
		
		
		
		bw.write("<html>"+"<head>"+"<title>"+"Kontoauszug    "+"Krn.: " + acc.getAccountNumber()+"  "+acc.getAccountOwner()+"</title>"+"</head>"+"<body>");
		
		bw.write("Kontoauszug"+"<br><br>");

		bw.write("<b>"+acc.getAccountOwner()+"<br>"+ "Kontonummer: " +acc.getAccountNumber()+"<br> "+"Aktueller Kontostand: "+acc.getAccountBalance()+"<br><br>"+"</b>");
		
		bw.write("<table border=\"1\"><colgroup><col width=\"400\" /><col width=\"400\" /><col width=\"150\" /></colgroup>");
		bw.write("<tr><td>Buchungsdatum</td><td>Vorgang</td><td>Betrag</td></tr>");
		
		
		while(iter.hasNext()) {
			bw.write(iter.next().getAmount()+"");
		}
		
		bw.write("</table>");
		bw.write("</body></html>");
		bw.close();
	}

}
